package common

type Common struct {
	InDate        int64  `json:"inDate" xorm:"created"`
	InUserID      string `json:"inUserId"`
	InUserName    string `json:"inUserName"`
	InUserPhone   string `json:"inUserPhone"`
	EditDate      int64  `json:"editDate" xorm:"updated"`
	EditUserID    string `json:"editUserId"`
	EditUserName  string `json:"editUserName"`
	EditUserPhone string `json:"editUserPhone"`
}

func (this *Common) Create(u IUser) string {
	this.InUserID = u.GetID()
	this.InUserName = u.GetName()
	this.InUserPhone = u.GetPhone()
	this.EditUserID = u.GetID()
	this.EditUserName = u.GetName()
	this.EditUserPhone = u.GetPhone()
	return "EditUserID,EditUserName,EditUserPhone"
}

func (this *Common) GetInUserID() string {
	return this.InUserID
}

func (this *Common) GetInUserName() string {
	return this.InUserName
}

func (this *Common) GetInUserPhone() string {
	return this.InUserPhone
}

func (this *Common) GetEditUserID() string {
	return this.EditUserID
}

func (this *Common) GetEditUserName() string {
	return this.EditUserName
}

func (this *Common) GetEditUserPhone() string {
	return this.EditUserPhone
}

//隐藏用户信息
func (this *Common) Hide() {
	this.InUserName = hideName(this.InUserName)
	this.EditUserName = hideName(this.EditUserName)
	this.InUserPhone = hidePhone(this.InUserPhone)
	this.EditUserPhone = hidePhone(this.EditUserPhone)
}

func hideName(s string) string {
	name := []rune(s)
	if len(name) == 2 {
		s = string(name[:1]) + "**"
	} else if len(name) > 2 {
		s = string(name[:1]) + "**"
	}
	return s
}

func hidePhone(phone string) string {
	if len(phone) >= 11 {
		return phone[:3] + "****" + phone[len(phone)-4:]
	}
	return phone
}

func (this *Common) HideAll() {
	this.InUserName = "匿名"
	this.InUserPhone = "匿名"
	this.EditUserName = "匿名"
	this.EditUserPhone = "匿名"
}
